#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

#define LL long long

queue<int> a , b;


int main(){
	int n , k1 , k2;
	scanf("%d %d",&n,&k1);
	for(int i = 0 ; i < k1 ; i ++){
		int temp;
		scanf("%d",&temp);
		a.push(temp);	
	}
	scanf("%d",&k2);
	for(int i = 0 ; i < k2 ; i ++){
		int temp;
		scanf("%d",&temp);
		b.push(temp);
	}

	int win , sum = 0;
	do{
		int topA = a.front();
		int topB = b.front();
		a.pop();
		b.pop();
		if(topA > topB){
			a.push(topB);
			a.push(topA);
		}else{
			b.push(topA);
			b.push(topB);
		}
		
		sum ++;
		if(a.empty() || b.empty())
			break;
		
		if(sum >= 10000){
			printf("-1\n");
			return 0;
		}
		
	}while(true);
	
	if(a.empty())
		win = 2;
	else
		win = 1;
	printf("%d %d\n",sum,win);
	
	return 0;
}